package com.ruoyi.web.controller.seed;

import java.util.List;

import com.ruoyi.common.annotation.PropertyInject;
import com.ruoyi.common.enums.InjectType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SeedReturn;
import com.ruoyi.system.service.ISeedReturnService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 种子退回信息Controller
 *
 * @author ruoyi
 * @date 2021-07-08
 */
@RestController
@RequestMapping("/seed/return")
public class SeedReturnController extends BaseController
{
    @Autowired
    private ISeedReturnService seedReturnService;

    /**
     * 查询种子退回信息列表
     */
    @PreAuthorize("@ss.hasPermi('seed:return:list')")
    @GetMapping("/list")
    public TableDataInfo list(SeedReturn seedReturn)
    {
        startPage();
        List<SeedReturn> list = seedReturnService.selectSeedReturnList(seedReturn);
        return getDataTable(list);
    }

    /**
     * 导出种子退回信息列表
     */
    @PreAuthorize("@ss.hasPermi('seed:return:export')")
    @Log(title = "种子退回信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SeedReturn seedReturn)
    {
        List<SeedReturn> list = seedReturnService.selectSeedReturnList(seedReturn);
        ExcelUtil<SeedReturn> util = new ExcelUtil<SeedReturn>(SeedReturn.class);
        return util.exportExcel(list, "种子退回信息数据");
    }

    /**
     * 获取种子退回信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('seed:return:query')")
    @GetMapping(value = "/{seedReturnId}")
    public AjaxResult getInfo(@PathVariable("seedReturnId") Long seedReturnId)
    {
        return AjaxResult.success(seedReturnService.selectSeedReturnById(seedReturnId));
    }

    /**
     * 新增种子退回信息
     */
    @PreAuthorize("@ss.hasPermi('seed:return:add')")
    @Log(title = "种子退回信息", businessType = BusinessType.INSERT)
    @PostMapping
    @PropertyInject(type = InjectType.Insert)
    public AjaxResult add(@RequestBody SeedReturn seedReturn)
    {
        return toAjax(seedReturnService.insertSeedReturn(seedReturn));
    }

    /**
     * 修改种子退回信息
     */
    @PreAuthorize("@ss.hasPermi('seed:return:edit')")
    @Log(title = "种子退回信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @PropertyInject(type = InjectType.Update)
    public AjaxResult edit(@RequestBody SeedReturn seedReturn)
    {
        return toAjax(seedReturnService.updateSeedReturn(seedReturn));
    }

    /**
     * 删除种子退回信息
     */
    @PreAuthorize("@ss.hasPermi('seed:return:remove')")
    @Log(title = "种子退回信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{seedReturnIds}")
    public AjaxResult remove(@PathVariable Long[] seedReturnIds)
    {
        return toAjax(seedReturnService.deleteSeedReturnByIds(seedReturnIds));
    }
}
